package DataStructure.graph;

import DataStructure.linear.Queue;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class KruskalMSTTest {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(KruskalMSTTest.class.getClassLoader().getResourceAsStream("min_create_tree_test.txt")));
        int total = Integer.parseInt(br.readLine());
        EdgeWeightedGraph G = new EdgeWeightedGraph(total);

        int edgeNumber = Integer.parseInt(br.readLine());
        for (int e = 1; e <= edgeNumber; e++) {
            String line = br.readLine();
            String[] strs = line.split(" ");
            int v = Integer.parseInt(strs[0]);
            int w = Integer.parseInt(strs[1]);
            double weight = Double.parseDouble(strs[2]);
            //构建加权五香边
            Edge edge = new Edge(v, w, weight);
            G.addEdge(edge);
        }

        KruskalMST MST = new KruskalMST(G);

        //获取最小生成树的所有边
        Queue<Edge> edges = MST.edges();
        for (Edge e : edges) {
            int v = e.either();
            int w = e.other(v);
            double weight = e.weight();
            System.out.println(v+"-"+w+"::"+weight);
        }
    }
}
